True if any item in target equals value, false otherwise (including when target is empty).
list_contains(target, value) -> bool| Name | Type |
|---|---|
target | list |
value | element |
bool
true if any item in target equals value, false otherwise (including when target is empty).
A plain left-to-right search - target does not need to be sorted, and nothing about calling this changes target itself. Useful for "have I already got one of these" checks - a key already collected, a name already on a high-score table - before deciding whether to add another. If you also want to know where the value is, list_find gives its place, or -1 if it is not there.
This is for a list. A stack, a queue and a set each have their own, with the same job: stack_contains, queue_contains and set_contains. Giving one of them to list_contains is refused when the game is checked, and the message names the right one.
/// @type {list<int>}
var scores = [10, 20, 30];
var has20 = list_contains(scores, 20); // true
var has99 = list_contains(scores, 99); // false



A plain left-to-right search (find, the GBA module's own alias for std::find) - O(n) in how many items target holds, same cost as writing the loop by hand. Fine for the small, bounded lists this hardware ever holds; nothing about target needs to be sorted.